package com.zhouliang.login.controller;

import com.zhouliang.error.StatusCode;
import com.zhouliang.login.commom.RegisterResponse;
import com.zhouliang.util.CommonResponse;
import com.zhouliang.login.service.LoginService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/douyin/user")
public class LoginController {
    private final static Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private LoginService loginService;

    @PostMapping("/register")
    //TODO:这只是一个大概的代码框架演示，具体的逻辑需要仔细实现。
    public CommonResponse register(@RequestParam("username") String username,
                                   @RequestParam("password") String password) {
        Long userId = null;
        String token = null;
        try {
            userId = loginService.registerUser(username, password);
        } catch (Exception e) {
            logger.error(e.toString());
            return RegisterResponse.fail(StatusCode.REGISTERERROR);
        }
        token = "123";
        return RegisterResponse.ok(StatusCode.SUCCESS, userId, token);
    }
}
